]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
workspace: Use AppIcon.app to check action-support by the drag source
authorJonas Dreßler <verdre@v0yd.nl>
Fri, 2 Aug 2019 10:58:34 +0000 (12:58 +0200)
committerFlorian Müllner <florian.muellner@gmail.com>
Wed, 18 Sep 2019 17:14:16 +0000 (17:14 +0000)
`AppIcon.shellWorkspaceLaunch()` can easily be replaced by checking for
`AppIcon.app` and calling `AppIcon.app.open_new_window()` directly.

For compatibility and to prevent breaking extensions implementing the
function, keep supporting the `shellWorkspaceLaunch` API in AppIcon
while logging a deprecation warning. Also keep supporting the API on
drag sources (without deprecating it) to allow extensions to define
custom actions on their drag sources.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/121

js/ui/appDisplay.js
js/ui/workspace.js
js/ui/workspaceThumbnail.js

index d61329fd4dbdcce90a182a6e73e7183f4a82fb5f..9b61d4e26fb22b06089751bfee4556fdd23b200c 100644 (file)
@@ -2222,6 +2222,9 @@ var AppIcon = class AppIcon {
     }
 
     shellWorkspaceLaunch(params) {
+        let { stack } = new Error();
+        log(`shellWorkspaceLaunch is deprecated, use app.open_new_window() instead\n${stack}`);
+
         params = Params.parse(params, { workspace: -1,
                                         timestamp: 0 });
 
index faf4f8aa74f6214b6828633fa9829c3bf3b326c3..39b59f9d587a13eaa8c903d01c9f4d56d269106a 100644 (file)
@@ -1994,13 +1994,20 @@ var Workspace = class {
     handleDragOver(source, _actor, _x, _y, _time) {
         if (source.realWindow && !this._isMyWindow(source.realWindow))
             return DND.DragMotionResult.MOVE_DROP;
-        if (source.shellWorkspaceLaunch)
+        if (source.app)
+            return DND.DragMotionResult.COPY_DROP;
+        if (!source.app && source.shellWorkspaceLaunch)
             return DND.DragMotionResult.COPY_DROP;
 
         return DND.DragMotionResult.CONTINUE;
     }
 
     acceptDrop(source, actor, x, y, time) {
+        let workspaceManager = global.workspace_manager;
+        let workspaceIndex = this.metaWorkspace
+            ? this.metaWorkspace.index()
+            : workspaceManager.get_active_workspace_index();
+
         if (source.realWindow) {
             let win = source.realWindow;
             if (this._isMyWindow(win))
@@ -2022,12 +2029,15 @@ var Workspace = class {
             if (metaWindow.get_monitor() != this.monitorIndex)
                 metaWindow.move_to_monitor(this.monitorIndex);
 
-            let workspaceManager = global.workspace_manager;
-            let index = this.metaWorkspace ? this.metaWorkspace.index() : workspaceManager.get_active_workspace_index();
-            metaWindow.change_workspace_by_index(index, false);
+            metaWindow.change_workspace_by_index(workspaceIndex, false);
+            return true;
+        } else if (source.app) {
+            source.app.open_new_window(workspaceIndex);
             return true;
-        } else if (source.shellWorkspaceLaunch) {
-            source.shellWorkspaceLaunch({ workspace: this.metaWorkspace ? this.metaWorkspace.index() : -1,
+        } else if (!source.app && source.shellWorkspaceLaunch) {
+            // While unused in our own drag sources, shellWorkspaceLaunch allows
+            // extensions to define custom actions for their drag sources.
+            source.shellWorkspaceLaunch({ workspace: workspaceIndex,
                                           timestamp: time });
             return true;
         }
index 0c9bed12abcd8f7e6c766cd4ed78ef484ba1e2eb..e3a24e9d4f72015e909be95e9be810163ac024e8 100644 (file)
@@ -572,7 +572,9 @@ var WorkspaceThumbnail = GObject.registerClass({
 
         if (source.realWindow && !this._isMyWindow(source.realWindow))
             return DND.DragMotionResult.MOVE_DROP;
-        if (source.shellWorkspaceLaunch)
+        if (source.app)
+            return DND.DragMotionResult.COPY_DROP;
+        if (!source.app && source.shellWorkspaceLaunch)
             return DND.DragMotionResult.COPY_DROP;
 
         return DND.DragMotionResult.CONTINUE;
@@ -597,8 +599,13 @@ var WorkspaceThumbnail = GObject.registerClass({
 
             metaWindow.change_workspace_by_index(this.metaWorkspace.index(), false);
             return true;
-        } else if (source.shellWorkspaceLaunch) {
-            source.shellWorkspaceLaunch({ workspace: this.metaWorkspace ? this.metaWorkspace.index() : -1,
+        } else if (source.app) {
+            source.app.open_new_window(this.metaWorkspace.index());
+            return true;
+        } else if (!source.app && source.shellWorkspaceLaunch) {
+            // While unused in our own drag sources, shellWorkspaceLaunch allows
+            // extensions to define custom actions for their drag sources.
+            source.shellWorkspaceLaunch({ workspace: this.metaWorkspace.index(),
                                           timestamp: time });
             return true;
         }
@@ -779,7 +786,10 @@ var ThumbnailsBox = GObject.registerClass({
 
     // Draggable target interface
     handleDragOver(source, actor, x, y, time) {
-        if (!source.realWindow && !source.shellWorkspaceLaunch && source != Main.xdndHandler)
+        if (!source.realWindow &&
+            !source.app &&
+            (source.app || !source.shellWorkspaceLaunch) &&
+            source != Main.xdndHandler)
             return DND.DragMotionResult.CONTINUE;
 
         let canCreateWorkspaces = Meta.prefs_get_dynamic_workspaces();
@@ -836,7 +846,9 @@ var ThumbnailsBox = GObject.registerClass({
         if (this._dropWorkspace != -1) {
             return this._thumbnails[this._dropWorkspace].acceptDropInternal(source, time);
         } else if (this._dropPlaceholderPos != -1) {
-            if (!source.realWindow && !source.shellWorkspaceLaunch)
+            if (!source.realWindow &&
+                !source.app &&
+                (source.app || !source.shellWorkspaceLaunch))
                 return false;
 
             let isWindow = !!source.realWindow;
@@ -853,9 +865,16 @@ var ThumbnailsBox = GObject.registerClass({
                 if (source.metaWindow.get_monitor() != thumbMonitor)
                     source.metaWindow.move_to_monitor(thumbMonitor);
                 source.metaWindow.change_workspace_by_index(newWorkspaceIndex, true);
-            } else if (source.shellWorkspaceLaunch) {
+            } else if (source.app) {
+                source.app.open_new_window(newWorkspaceIndex);
+            } else if (!source.app && source.shellWorkspaceLaunch) {
+                // While unused in our own drag sources, shellWorkspaceLaunch allows
+                // extensions to define custom actions for their drag sources.
                 source.shellWorkspaceLaunch({ workspace: newWorkspaceIndex,
                                               timestamp: time });
+            }
+
+            if (source.app || (!source.app && source.shellWorkspaceLaunch)) {
                 // This new workspace will be automatically removed if the application fails
                 // to open its first window within some time, as tracked by Shell.WindowTracker.
                 // Here, we only add a very brief timeout to avoid the _immediate_ removal of the